package com.neu.wangxiaoyang.servlet;

import com.neu.wangxiaoyang.service.VisitAddService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet(name = "VisitAddServlet", urlPatterns = {"/VisitAddServlet.do"})
public class VisitAddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        Map<String ,String []> map =request.getParameterMap();
        VisitAddService vs=new VisitAddService();
        int row=vs.VisitSave(map);

        if(row>0){
            System.out.println("插入成功");
            response.sendRedirect(request.getContextPath()+"/commons/success.jsp");
        }else {
            System.out.println("插入失败");
            response.sendRedirect(request.getContextPath()+"/commons/fail.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
